package cn.young.javalearning.designpattern.singleton.register;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ContainerSingleton {
    private static final Map<String, Object> ioc = new ConcurrentHashMap<>();

    private ContainerSingleton(){}

    public static final ContainerSingleton getInstance(String name) throws Exception {
        synchronized (ioc){
            if(ioc.get(name) == null) {
                ioc.put(name, Class.forName(name).newInstance());
            }
        }
        return (ContainerSingleton) ioc.get(name);
    }
}
